
<h2 style='text-align:center'>区域数据库管理</h2>

<div style='text-indent:30px;margin:20px auto'>
	开通状态:
	<select id="MainCounty_CityOpenStat">
		<option value="1">全部城市</option>
		<option value="2">已开通城市</option>
		<option value="3">未开通城市</option>
	</select>
</div>

<div style=''>
	<div id='LoginCityArea' style='text-align:center'>
		<select id="MainCounty_Province"></select>
		<select id="MainCounty_City"></select>
		<select id="MainCounty_County"></select>
	</div>

	<div style='margin:20px auto;display:flex'>
		<div style='width:100px;text-align:right'>库　址：</div>
		<div style='flex:1'>
			<input id='MainCounty_DbHost' style='width:230px' />
		</div>
	</div>
	<div style='margin:20px auto;display:flex'>
		<div style='width:100px;text-align:right'>库　名：</div>
		<div style='flex:1'>
			<input id='MainCounty_DbName' style='width:230px' />
		</div>
	</div>
	<div style='margin:20px auto;display:flex'>
		<div style='width:100px;text-align:right'>验证码：</div>
		<div style='flex:1'>
			<input id='MainCounty_VCode' style='width:70px' />　
			<img src="interface.php?type=code" onclick="ChangeCode(this)" id='MainCounty_CodeImg' alt="点击" style='height:40px' align='top' />
		</div>
	</div>

	<div style='text-align:center'><button id='MainCounty_Sub'>修改</button></div>
</div>

<script>

//获取当前选择的开通状态
function GetOpenType(){
	return $('#MainCounty_CityOpenStat').find('option:selected').val();
}


//切换开通城市的状态选择
$('#MainCounty_CityOpenStat').change(function(){
	MainCountryCity();
});
	
MainCountryCity();


function MainCountryCity(OpenStat){
	//===== ### 获取全部城市数据
	var cache_CityFull = 'http://shop-cache-upyun.bm123.top/CityInfo/CityFull.html';
	var sess_CityFull = 'local_FullCityInfo';
	//cache_CityFull = '';
	//sess_CityFull = '';
	sca({'type':'GetCityFullInfo'},function(CityFull){
		if(/^Gets\(\[{.*\)$/.test(CityFull)){
			var CityFull = JSON.parse(CorsBackTrim(CityFull));
		}else if(/^\[{"id":.*}\]$/.test(CityFull)){
			var CityFull = JSON.parse(CityFull);
		}
		if(CityFull){
			//===== ### 获取已开通城市数据
			var sess_CityOpen = 'sess_OpenCityInfoAdmin';
			if(OpenStat){
				sessionStorage.sess_OpenCityInfoAdmin = '';	//清空sess缓存
			}
			sess_CityOpen = '';
			sca({'type':'GetCityFullInfo',"open_type":1},function(CityOpen){
				if(/^Gets\(\[{.*\)$/.test(CityOpen)){
					var CityOpen = JSON.parse(CorsBackTrim(CityOpen));
				}else if(/^\[{"id":.*}\]$/.test(CityOpen)){
					var CityOpen = JSON.parse(CityOpen);
				}
				if(CityOpen){
					City_ParseCity(CityFull,CityOpen,GetOpenType(),MainCounty_Province,MainCounty_City,MainCounty_County,function(){
						MainCounty_ViewDbInfoForCounty(MainCounty_County,MainCounty_DbHost,MainCounty_DbName);
					});
				}
			},after_url,sess_CityOpen);
		}
	},after_url,sess_CityFull,cache_CityFull,2000);
}




	//提交修改城市对应库址，库名
	$('#MainCounty_Sub').click(function(){
		var Host = ChangeChar($('#MainCounty_DbHost').val().trim());
		var Name = ChangeChar($('#MainCounty_DbName').val().trim());
		var CountyCode = sessionStorage.MainCounty_Code;
		if(Host == sessionStorage.MainCounty_DbHost && Name == sessionStorage.MainCounty_DbName){
			A('数据没有变动 ！');return;
		}

		var VCode = $('#MainCounty_VCode').val().trim();
		//Field_Check(/^\w{4}$/,Code,'验证码不正确！');		//检测库名
	
		if(Host && !ChacekIpFormart(Host)){
			A('iP地址不合法！');return;							//检测ip
		}
		Field_Check(/^$|^[a-z]\w{1,29}$/,Name,'库名不合法！');		//检测库名

		var data = {
			type:'UpdateShareCityInfo',
			host:Host,
			name:Name,
			code:VCode,
			county_code:CountyCode
		};
		Ajax2(data,function(res){
			C(res);
			switch(res){
				case 'ok':
					A('修改成功!');
					MainCountryCity(1);
					break;
				case 'err3':
				case 'err1':
					A('验证码不正确!');
					$('#MainCounty_Code').val('');
					ChangeCode(MainCounty_CodeImg);
					break;
				case 'err4':
				case 'err2':
					A('修改失败');
					break;
			}
		},'interface.php');
	});

</script>
